﻿using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GrainManage.Data.Provider
{
    public class MySqlTransactionProvider : IProvider
    {
        private DbConnection con;
        public MySqlTransactionProvider(string connectionString) { con = new MySqlConnection(connectionString); }

        public MySqlTransactionProvider(DbConnection con) { this.con = con; }

        public DbConnection Connection
        {
            get { return con; }
        }

        public DbCommand GetCommand(string cmdText, System.Data.Common.DbConnection connection)
        {
            var cmd = new MySqlCommand(cmdText, connection as MySqlConnection);
            cmd.CommandType = CommandType.StoredProcedure;
            return cmd;
        }

        public DbDataAdapter GetAdapter(string selectCmdText)
        {
            var cmd = GetCommand(selectCmdText, Connection);
            return new MySqlDataAdapter(cmd as MySqlCommand);
        }

        public DbParameter GetDbParameter(string paraName, object value, System.Data.ParameterDirection direction = ParameterDirection.Input)
        {
            var parameter = new MySqlParameter(paraName, value);
            parameter.Direction = direction;
            return parameter;
        }
    }
}
